define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form, Template, tabletreegrid) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    "index_url": "device/devicelist/index",
                    "add_url": "device/devicelist/add",
                    "edit_url": "device/devicelist/edit",
                    // "del_url": "device/devicelist/del",
                    "multi_url": "device/devicelist/multi",
                    "table": "auth_rule"
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: '',
                columns: [
                    [
                        // {field: 'state', checkbox: true,},
                        {field: 'id', title: '编号'},
                        
                        {field: 'name', title: '设备名称'},
                        {field: 'img', title: '设备图片', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: "edit",
                                    text: "编辑",
                                    classname: "btn btn-xs btn-info btn-dialog",
                                    icon: "fa fa-eye",
                                    url: "device/devicelist/edit",
                                },
                            ],
                        }
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            var btnSuccessEvent = function (data, ret) {
                table.bootstrapTable('refresh');
                return false;
                // if ($(this).hasClass("btn-change")) {
                //     var index = $(this).data("index");
                //     var row = Table.api.getrowbyindex(table, index);
                //     row.ismenu = $("i.fa.text-gray", this).length > 0 ? 1 : 0;
                //     table.bootstrapTable("updateRow", {index: index, row: row});
                // } else if ($(this).hasClass("btn-delone")) {
                //     if ($(this).closest("tr[data-index]").find("a.btn-node-sub.disabled").length > 0) {
                //         $(this).closest("tr[data-index]").remove();
                //     } else {
                //         table.bootstrapTable('refresh');
                //     }
                // } else if ($(this).hasClass("btn-dragsort")) {
                //     table.bootstrapTable('refresh');
                // }
                // Fast.api.refreshmenu();
                // return false;
            };
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
